import mongoose from 'mongoose';
const Schema = mongoose.Schema;

// AccessTokens 表
const accessTokensSchema = new Schema({
  createdAt: { default: Date.now, type: Date },
  status: { default: 1, type: Number }, // 固定为 1 表示当前有效
  token: { required: true, type: String },
  updatedAt: { default: Date.now, type: Date },
});

// ScheduledTasks 表
const scheduledTasksSchema = new Schema({
  content: { required: true, type: String },
  createdAt: { default: Date.now, type: Date },
  status: { default: 0, type: Number }, // 0 表示未完成，1 表示已完成
  target: { required: true, type: String },
  time: { required: true, type: Date },
  updatedAt: { default: Date.now, type: Date },
});

// ForwardingConfigs 表
const forwardingConfigsSchema = new Schema({
  createdAt: { default: Date.now, type: Date },
  forwardRoom: { required: true, type: String },
  roomTopic: { required: true, type: String },
  status: { default: 0, type: Number }, // 0 表示已配置，1 表示新增配置
  updatedAt: { default: Date.now, type: Date },
  userName: { required: true, type: String },
});

// Bots 表
const botsSchema = new Schema({
  botName: { required: true, type: String },
  createdAt: { default: Date.now, type: Date },
  status: { default: 0, type: Number }, // 0 表示未启动，1 表示已启动
  updatedAt: { default: Date.now, type: Date },
});

// 创建模型
export const AccessToken = mongoose.model('AccessToken', accessTokensSchema);
export const ScheduledTask = mongoose.model('ScheduledTask', scheduledTasksSchema);
export const ForwardingConfig = mongoose.model('ForwardingConfig', forwardingConfigsSchema);
export const Bot = mongoose.model('Bot', botsSchema);
